package com.vast.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vast.admin.annotation.UseToken;
import com.vast.admin.entity.LawsuitFlow;
import com.vast.admin.entity.enums.QueryOrderEnum;
import com.vast.admin.service.impl.LawsuitFlowService;
import com.vast.common.annotation.Log;
import com.vast.common.core.domain.entity.SysUser;
import com.vast.common.utils.SecurityUtils;
import com.vast.common.constant.MessageCode;
import com.vast.common.core.domain.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaohao
 * @since 2019-04-03
 */
@Api(value="诉讼流程操作相关的api",tags= {"诉讼流程模块"})
@RestController
@RequestMapping("/manager/lawsuitFlow")
public class LawsuitFlowController extends ApiController {

	@Autowired
	private LawsuitFlowService service;


	@ApiOperation(value = "查询列表信息", notes = "通过条件查询列表")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", name = "size", value = "分页条数", dataType = "int", defaultValue = "10", required = false),
			@ApiImplicitParam(paramType = "query", name = "current", value = "页码,起始值:1", dataType = "int", defaultValue = "1", required = false),
			@ApiImplicitParam(paramType = "query", name = "listMode", value = "是否集合模式:true不进行分页直接返回所有结果集", dataType = "boolean", defaultValue = "false", required = false),
			@ApiImplicitParam(paramType = "query", name = "queryItems", value = "查询条件,json集合", defaultValue = "account,EQ,13419519796;", dataType = "String", required = false),
			@ApiImplicitParam(paramType = "query", name = "orderField", value = "排序字段,多个','分隔", defaultValue = "create_time", dataType = "String",  required = false),
			@ApiImplicitParam(paramType = "query", name = "order", value = "排序类型: ASC/DESC", dataType = "QueryOrderEnum",  required = false)
	})
	@GetMapping("/page")
	public Result<IPage<LawsuitFlow>> page(@ApiParam(hidden = true) Page<LawsuitFlow> page, boolean listMode, String queryItems, String orderField, QueryOrderEnum order) {
		return new Result<IPage<LawsuitFlow>>(MessageCode.SUCCESS, "获取成功", service.queryList(page, listMode, queryItems, orderField,order));

	}

	@ApiOperation(value = "添加或更新", notes = "添加或更新")
	@UseToken
	@PostMapping("/addOrUpdate")
	@Log(title = "添加或更新企业")
	public Result<LawsuitFlow> addOrUpdate(@RequestBody @ApiParam(name="LawsuitFlow",value="Role信息",required=true) LawsuitFlow LawsuitFlow) {
		if(LawsuitFlow != null) {
			SysUser manager = SecurityUtils.getLoginUser().getUser();
			boolean flag  = service.addOrUpdate(manager, LawsuitFlow);
			if(flag){
				return new Result<LawsuitFlow>(MessageCode.SUCCESS, "成功", LawsuitFlow);
			}else{
				return new Result<LawsuitFlow>(MessageCode.ERROR, "失败");
			}
		}else {
			return new Result<LawsuitFlow>(MessageCode.PARAM_ERROR, "参数错误");
		}
	}

	@ApiOperation(value = "通过id获取信息", notes = "通过id获取信息")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token", dataType = "String", required = true)})
	@GetMapping("/info/{id}")
	@UseToken
	@Log(title = "通过id获取信息")
	public Result<LawsuitFlow> info(@PathVariable("id") Long id) {
		if(id != null && id.longValue() > 0){
			SysUser manager = SecurityUtils.getLoginUser().getUser();
			LawsuitFlow bean = service.info(manager,id);
			if(bean != null){
				return new Result<LawsuitFlow>(MessageCode.SUCCESS, "获取成功", bean);
			}else{
				return new Result<LawsuitFlow>(MessageCode.ERROR, "获取失败");
			}
		}
		return new Result<LawsuitFlow>(MessageCode.PARAM_ERROR, "id不能为空");
	}

	@ApiOperation(value = "删除", notes = "删除")
	@UseToken
	@Log(title = "删除")
	@DeleteMapping("/delete")
	public Result<Boolean> delete( @RequestBody @ApiParam(name="ids",value="数据id数组,以','分隔",required=true) Long[] ids) {
		if(ids != null) {
			SysUser manager = SecurityUtils.getLoginUser().getUser();
			boolean flag  = service.delete(manager, ids);
			if(flag){
				return new Result<Boolean>(MessageCode.SUCCESS, "删除成功");
			}else{
				return new Result<Boolean>(MessageCode.ERROR, "删除失败");
			}
		}else {
			return new Result<Boolean>(MessageCode.PARAM_ERROR, "参数错误");
		}
	}

	@ApiOperation(value = "启/禁用模版", notes = "启/禁用模版")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", name = "id", value = "数据id", dataType = "Long", required = true),
			@ApiImplicitParam(paramType = "query", name = "status", value = "状态0-禁用 1-启用", dataType = "Integer", defaultValue="1", required = true)
	})
	@UseToken
	@Log(title = "启/禁用模版")
	@PostMapping("/enable")
	public Result enable(Long id, Integer status) {
		LawsuitFlow bean = service.getById(id);
		if(bean != null){
			bean.setStatus(status);
			service.saveOrUpdate(bean);
			return new Result(MessageCode.SUCCESS, "修改成功",true);
		}else{
			return new Result(MessageCode.ERROR, "此数据不存在");
		}

	}

}
